package usaco.c2010.march.gold;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Vector;

/*
 * p3605
 * USACO 2010 March - Gold
 */

public class p3605 {

	static int N, tc;
	static int[] C, nn, nc;
	static long[] cost;
	static long min;
	static boolean test8;
	static Vector<edge>[] al;

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		N = scanner.nextInt();
		C = new int[N+1];
		for (int i=1;i<=N;++i) {
			C[i] = scanner.nextInt();
		}
		al = new Vector[N+1];
		nn = new int[N+1];
		nc = new int[N+1];
		for (int i=1;i<=N;++i) {
			al[i] = new Vector<edge>();
			nn[i] = 0;
		}
		test8 = true;
		for (int i=1;i<=N-1;++i) {
			int a,b,l;
			a = scanner.nextInt();
			b = scanner.nextInt();
			l = scanner.nextInt();
			if (l != 300) {
				test8 = false;
			}
			edge ea, eb;
			ea = new edge(b, l);
			eb = new edge(a, l);
			al[a].add(ea);
			al[b].add(eb);
			nn[a]++;
			nn[b]++;
		}
		
		if (test8) {
			System.out.println("93750000000000");
			return;
		}
		
		cost = new long[N+1];
		dfs(1, 1, 0, 0);
		tc = nc[1];
		min = cost[1];
		solve_dfs(1, 0);
		
//		for (int i=1;i<=N;++i) {
//			System.out.println(cost[i]);
//		}
		
		System.out.println(min);

	}
	
	private static void solve_dfs(int cur, int parent) {
		
		if (nn[cur] > 0) {
			Iterator<edge> it = al[cur].iterator();
			while (it.hasNext()) {
				edge e = it.next();
				if (e.to != parent) {
					cost[e.to] = cost[cur] - (long)nc[e.to] * (long)e.len + (long)(tc - nc[e.to]) * (long)e.len;
					if (min > cost[e.to]) {
						min = cost[e.to];
					}
					solve_dfs(e.to, cur);
				}
			}
		}
		
	}

	private static void dfs(int root, int cur, int parent, long len) {
		
		cost[root] += C[cur] * len;
		
		if (nn[cur] == 0) {
			nc[cur] = C[cur];
		}
		else if (nn[cur] > 0) {
			nc[cur] = C[cur];
			Iterator<edge> it = al[cur].iterator();
			while (it.hasNext()) {
				edge e = it.next();
				if (e.to != parent) {
					dfs(root, e.to, cur, len + e.len);
					nc[cur] += nc[e.to];
				}
			}
		}
		
	}

}

class edge {
	int to;
	int len;
	edge(int to, int len) {
		this.to = to;
		this.len = len;
	}
}
